﻿
var jq = jQuery;
jq.noConflict();
var basePath="";
jq(function(){
	basePath=jq("a#basePath").attr("href");
});
function realPath(path){
	return basePath+path;
}
function insertLinkImg(aclass,imgpath){
	jq("a."+aclass).prepend("<img alt='"+aclass+"' src='"+realPath(imgpath)+"' />");
}
//jq(function(){
//	enhance({
//		loadStyles : [ 
////		{ href : 'css/ie-fixes.css', iecondition : 'all' },
//		{ href : 'css/ie.css', iecondition : 6 } 
//		]
//	});
//});
jq(function() {
	//	var before= new Date();
	insertLinkImg("sendmail","css/images/easyicon-mail-send-12953.png");
	insertLinkImg("list","css/images/EasyiconList.png");
	insertLinkImg("view","css/images/easyicon-view-37736.png");
	insertLinkImg("delete","css/images/EasyiconDelete.png");
	insertLinkImg("deleteAll","css/images/EasyiconDeleteAll.png");
	//
	insertLinkImg("deleteUser","css/images/EasyiconDeleteUser.png");
	insertLinkImg("addUser","css/images/EasyiconAddUser.png");
	insertLinkImg("listUser","css/images/EasyiconListUser.png");
	//
	insertLinkImg("deleteRole","css/images/EasyiconDeleteUser.png");
	insertLinkImg("addRole","css/images/EasyiconAddUser.png");
	insertLinkImg("listRole","css/images/EasyiconListUser.png");
	//
	insertLinkImg("logout","css/images/EasyiconLogout.png");
	insertLinkImg("check","css/images/EasyiconChecked.png");
	insertLinkImg("upload","css/images/EasyiconUpload.png");
	insertLinkImg("download","css/images/EasyiconDownload3.png");
	insertLinkImg("add","css/images/EasyiconAdd.png");
	insertLinkImg("search","css/images/EasyiconSearch.png");
	insertLinkImg("forward","css/images/KnobForward.png");
	insertLinkImg("back","css/images/KnobLeft.png");
	insertLinkImg("modify","css/images/KnobAttention.png");
	insertLinkImg("edit","css/images/EasyiconEdit.png");
	insertLinkImg("cancel","css/images/easyicon-cancel-5245.png");
	insertLinkImg("ok","css/images/KnobValidGreen.png");
	insertLinkImg("message","css/images/KnobMessage.png");
	insertLinkImg("reset","css/images/KnobAttention.png");
	insertLinkImg("relate","css/images/KnobForward.png");
	insertLinkImg("enter","css/images/KnobForward.png");
	//	var after = new Date();
	//  alert("a prepend img\n"+(after-before));
	//material list 31,bom list 78
});
//--------------------------------
jq(function() {
	jq("#allMenuItems div").addClass("dropmenudiv_a");
	jq("#menuBar").dropdownMenu();
	jq("th").resizable();
});

//jq(function() {
//	jq("button#emptyCode").click(function() {
//		var data = jq("input#m_code").val();
//		if (data.length <= 0) {
//			jq.messager.alert("请先输入编码前缀，例如A1，Z9","");
//			return false;
//		}
//		var url = 'emptycode/' + data;
//		jq.post(url, function(data) {
//			jq("input#m_code").val(data);
//		});
//		return false;
//	});//reg
//});
//---------------------------------
jq(function (){
	jq(":checkbox.visibleFragment").change(function(){
		var select=jq(this).attr("checked");
		var element=jq(this).parent().find("div.visibleFragment");
//		alert(element);
		if(select){
			element.slideDown();
		}else{
			element.slideUp();
		}
	});
});
function reSlider(input){
	var pre=jq(input).attr("id");
	var inputId=pre;
	var percentId ="#"+pre+"_percent";
	var totalId = "#" + pre + "_total";
	var sliderId="#slider_"+pre;
	//var inputValue=0+inputValue,fix bug for see a string not number
	var inputValue=new Number(jq(input).val());
	var maxId ="#"+pre+"_max";
	var maxValue=new Number(jq(maxId).val());
	var totalValue=new Number(jq(totalId).val());
	if(inputValue<=maxValue){
		jq(inputId).val(inputValue.toFixed(2));
		var percent=inputValue.mul(100).div(totalValue);
		jq(percentId).val(percent);
		jq(sliderId).slider({"value":Math.ceil(percent)});
	}else{
		jq(inputId).val(maxValue.toFixed(2));
		var percent=maxValue.mul(100).div(totalValue);
		jq(percentId).val(percent);
		jq(sliderId).slider({"value":Math.ceil(percent)});
	}
}
function doSlider(slider, event, ui) {
	var preLen = "slider_".length;
	var id = jq(slider).attr("id");
	var pre = id.substring(preLen);
	var percentId = "#" + pre + "_percent";
	var inputId = "#" + pre;
	var totalId = "#" + pre + "_total";
	var maxId ="#"+pre+"_max";
	var maxValue=new Number(jq(maxId).val());
	var totalValue=new Number(jq(totalId).val());
	var inputValue=new Number(ui.value).mul(jq(totalId).val()).div(100);
	if(inputValue<=maxValue){
		jq(inputId).val(inputValue.toFixed(2));
		jq(percentId).val(ui.value);
		//has bug,such 520*62=32240,32240/520=61.9999999999
		//jq(percentId).val(inputValue*100/jq(totalId).val());
//		jq(percentId).val(inputValue.mul(100).div(totalValue));
	}else{
		jq(inputId).val(maxValue.toFixed(2));
//		jq(percentId).val(maxValue*100/jq(totalId).val());
		jq(percentId).val(maxValue.mul(100).div(totalValue));
	}
}
function doSliderInit(slider,event,ui){
	var preLen = "slider_".length;
	var id = jq(slider).attr("id");
	var pre = id.substring(preLen);
	var inputId = "#" + pre;
	var totalId = "#" + pre + "_total";
	var defaultPercentId ="#"+pre+"_defaultPercent";
	var defaultPercent=jq(defaultPercentId).val();
	defaultPercent=Math.ceil(defaultPercent);//fix bug because slider value is integer not decimal
//	jq(inputId).attr("readonly","readonly");
//	jq(slider).slider({"max":100,"step":1});
	jq(slider).slider({"value":defaultPercent});
	//input change listener
//	jq(inputId).change(function(){
//		reSlider(this);
//	});
	jq(inputId).keyup(function(){
		reSlider(this);
	});
}
jq(function() {
	jq(".ui_slider").slider( {
//only hand slider invoke doSlider		
//		change : function(event, ui) {
//			doSlider(this, event, ui);
//		},
		slide : function(event, ui) {
			doSlider(this, event, ui);
		},
		create:function(event,ui){
			doSliderInit(this,event,ui);
		}
	});
});
//-----------------------------------
jq(function() {
	jq(":checkbox.selectAll").click(function() {
		var select = jq(this).attr("checked");
		jq(this).parents("form").find(":checkbox").attr( {
			checked : select
		});
	});

	jq(":radio.selectAll").click(function() {
		var value = jq(this).val();
		jq(this).parents("form").find(":radio[value=" + value + "]").attr( {
			checked : 'checked'
		});
	});
});
jq(function() {
//	jq(".askAgain").not("[type=button]").click(function() {
//		return confirm("危险操作，确定执行？！");
//	});
	jq(".askAgain").not("[type=button]").mousedown(function() {
		var link = jq(this);
		var d = jq("<div></div");
		d.dialog({
			resizable : false,
			modal : true,
			title : "注意,危险操作，确定执行？！",
			buttons : {
				"确定" : function() {
					location.href = link.attr("href");
				},
				"取消" : function() {
					jq(this).dialog("close");
				}
			}
		});
		return false;
	});

});
jq(function(){
	jq(".hjPanel").hjPanel();
	jq(".hjTree").hjTree();
});
//jq(function() {
//	//	var before= new Date();
////	alert("here");
//	jq.ifixpng("css/blank.gif");
//	jq("img[src$=.png]").ifixpng();
////	alert("ok");FIXME wrong here
//	//    var after = new Date();
//	//    alert("fix ie png\n"+(after-before));
//});



